﻿using DotNetCore.CAP;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using UnitOfWorkCore.Domain.Abstractions;
using UnitOfWorkCore.Domain.Entities;

namespace UnitOfWorkCore.Application.Commands
{
    public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Unit>
    {
        private readonly IUnitOfWork _unitOfWork;
        private readonly IRepository<User> _userRepository;
        private readonly ICapPublisher _capPublisher;
        public CreateUserCommandHandler(IRepository<User> userRepository, ICapPublisher capPublisher, IUnitOfWork unitOfWork)
        {
            _userRepository = userRepository;
            _capPublisher = capPublisher;
            _unitOfWork = unitOfWork;
        }


        public async Task<Unit> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            await _userRepository.InsertSingleData(new User("江北"));
            await _unitOfWork.SaveChangesAsync();
            return Unit.Value; // 返回 Unit.Value 表示操作成功完成  
        }
    }
}
